package com.zhbcm.outupload.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author 朝花不迟暮
 * @version 1.0
 * @date 2021/6/26 20:18
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer
{
    @Autowired
    private UploadProperties uploadProperties;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry)
    {
        registry.addResourceHandler("/**")
                .addResourceLocations("classpath:/META-INF/resources/")
                .addResourceLocations("classpath:/resources/")
                .addResourceLocations("classpath:/static/")
                .addResourceLocations("classpath:/public/");
        /*解释:
        /files/**: 相当于 别名的意思
        file:D:/图片/: 本地文件的路径*/
        // System.out.println("handler:  " + uploadProperties.getResourceHandler());
        registry.addResourceHandler(uploadProperties.getResourceHandler() + "**")
                .addResourceLocations(uploadProperties.getResourceLocations());
    }
}
